<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Hash;
use DB;
use Mail;
use Gregwar\Captcha\CaptchaBuilder;
use App\Http\Requests\HomeForgetPostRequest;
use App\Http\Requests\ForgetPostRequest;
use App\Http\Requests;

use App\Http\Controllers\Controller;

class Forgetcontroller extends Controller
{
	public function getForget()
    {
        //显示找回密码页
        return view('home.login.forget');
    }

    public function postFsuccess(Request $request)
    {
         // dd($request->all());
        // dd($request->only('username'));

       $email = DB::table('user')->where('email',$request->input('email'))->first();
        // dd($email);
        // dd($user->only('password'));
      //检测密码是否一致
       // dd($user);
       if(!$email){
            return back()->with('error','请输入正确邮箱');
       }else{
       		$token = DB::table('user')->where('email',$request->input('email'))->first();
       		$this->zhaohui($token->id,$token->token,$token->email);
            return view('home.login.fsuccess');
        }
    }



    //邮件发送
    public function zhaohui($id,$token,$email)
    {
        
       
         Mail::send('mail.fre', ['id'=>$id,'token'=>$token], function ($message)use($email) {
            $message->to($email)->subject('重置密码');
        });
        // return view('mail.fre');
        // $data['token'] = str_random(50);

    }
 
}

   

  
